package com.ieslab.servlet;

import java.io.Serializable;
import java.util.Date;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionEvent;

/**
 * 对于钝化/活化,其实就是让对象序列化/反序列化穿梭于内存与持久化存储设备中.因此实现HttpSessionActivationListener接口的JavaBean也需要实现Serializable接口.
 * <b>一定要实现Serializable接口</b>
 */
@WebListener
public class BaseSessionBeanListener implements HttpSessionActivationListener, Serializable {
	/**TODO*/
	private static final long serialVersionUID = -8702073420982131236L;
	private int id;
	private String name;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Default constructor. 
	 */
	public BaseSessionBeanListener() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpSessionActivationListener#sessionDidActivate(HttpSessionEvent)
	 */
	public void sessionDidActivate(HttpSessionEvent se) {
		System.out.println("sessionDidActivate=" + new Date(se.getSession().getCreationTime()));
	}

	/**
	 * @see HttpSessionActivationListener#sessionWillPassivate(HttpSessionEvent)
	 */
	public void sessionWillPassivate(HttpSessionEvent se) {
		System.out.println("sessionWillPassivate=" + new Date(se.getSession().getCreationTime()));
	}
}
